<template>
  <div>
    <Breadcrumb :titles="titles"></Breadcrumb>
    <div class="body">
      <div class="body-left">
        <div class="project">
          <el-form
            :model="basicForm"
            label-position="top"
            :rules="basicRules"
            ref="basicFormRef"
          >
            <!-- 基本信息 -->
            <div class="project-part">
              <div class="project-part-title">基本信息</div>
              <div class="project-part-content">
                <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item
                      label="平台名称"
                      prop="platformName"
                    >
                      <el-input
                        v-model="basicForm.platformName"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="项目类型">
                      <el-select
                        placeholder="项目类型"
                        v-model="basicForm.projectType"
                        clearable
                      >
                        <el-option
                          v-for="item in projectTypeOptions"
                          :key="item.dictValue"
                          :label="item.dictText"
                          :value="item.dictValue"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item
                      label="上会时间"
                      prop="projectName"
                    >
                      <el-date-picker
                        v-model="basicForm.shTime"
                        type="date"
                        placeholder="上会时间"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item label="签约时间">
                      <el-date-picker
                        v-model="basicForm.qyTime"
                        type="date"
                        placeholder="签约时间"
                      >
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item
                      label="联系人"
                      prop="contactPerson"
                    >
                      <el-input
                        v-model="basicForm.contactPerson"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item
                      label="联系方式"
                      prop="contactPerson"
                    >
                      <el-input
                        v-model="
                          basicForm.contactInformation
                        "
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="16">
                    <el-form-item
                      label="项目内容"
                      prop="projectContent"
                    >
                      <el-input
                        type="textarea"
                        v-model="basicForm.projectContent"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </div>

            <!-- 项目情况 -->
            <div class="project-part">
              <div class="project-part-title">项目情况</div>
              <div class="project-part-content">
                <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item label="进展情况">
                      <el-input
                        type="textarea"
                        v-model="
                          basicForm.projectSituation.jzqk
                        "
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="存在问题">
                      <el-input
                        type="textarea"
                        v-model="
                          basicForm.projectSituation.czwt
                        "
                      ></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="下一步建议">
                      <el-input
                        type="textarea"
                        v-model="
                          basicForm.projectSituation.xybjy
                        "
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item label="备注">
                      <el-input
                        type="textarea"
                        v-model="
                          basicForm.projectSituation.bz
                        "
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-form>
        </div>
      </div>
      <div class="body-right">
        <div class="project-part-title">进度历史记录</div>
        <el-scrollbar>
          <div
            v-for="(item, index) in historyList"
            :key="index"
          >
            <div class="time" @click="clickTime(index)">
              <div
                :style="
                  item.expand ? { color: '#00BAFF' } : ''
                "
              >
                {{ item.createTime }}
              </div>
              <div
                :style="
                  item.expand ? { color: '#00BAFF' } : ''
                "
                v-if="item.expand"
                class="el-icon-arrow-up"
              ></div>
              <div v-else class="el-icon-arrow-right"></div>
            </div>

            <div v-if="item.expand" class="item">
              <div class="item-title">【进展情况】</div>
              <div class="item-text">{{ item.jzqk }}</div>
              <div class="item-title">【存在问题】</div>
              <div class="item-text">{{ item.czwt }}</div>
              <div class="item-title">【下一步建议】</div>
              <div class="item-text">{{ item.xybjy }}</div>
              <div class="item-title">【备注】</div>
              <div class="item-text">{{ item.bz }}</div>
            </div>
          </div>
        </el-scrollbar>
      </div>
    </div>
    <div class="line"></div>
    <el-button @click="saveInfo" class="save-btn"
      >保存</el-button
    >
  </div>
</template>

<script>
import Breadcrumb from '@/components/breadcrumb'
import {
  addProjectInfo,
  queryProjectDetail
} from '@/api/innovation'

import { getDictOptions } from '@/utils/dict'

export default {
  props: {
    pkid: String,
    title: String
  },
  components: {
    Breadcrumb
  },
  data() {
    return {
      basicForm: {
        platformName: '',
        projectType: '',
        shTime: '',
        qyTime: '',
        contactPerson: '',
        contactInformation: '',
        projectContent: '',
        projectSituation: {
          jzqk: '',
          czwt: '',
          xybjy: '',
          bz: ''
        }
      },
      basicRules: {},
      projectTypeOptions: [],
      historyList: [],
      currentItem: 0
    }
  },
  computed: {
    titles() {
      return [this.title]
    }
  },
  mounted() {
    this.queryTypeOptions()
    this.getDetailInfo()
  },
  methods: {
    // 项目分类
    async queryTypeOptions() {
      this.projectTypeOptions = await getDictOptions(
        'cotrunProjectType'
      )
    },

    // 获取项目详情
    getDetailInfo() {
      queryProjectDetail(this.pkid).then((res) => {
        if (res.success) {
          const data = res.data
          this.basicForm = data
          this.basicForm.projectSituation =
            data.projectSituationList[0]
          this.historyList = data.projectSituationList.map(
            (item, index) => {
              return {
                ...item,
                expand: index === 0 ? true : false
              }
            }
          )
        }
      })
    },

    // 保存信息
    saveInfo() {
      addProjectInfo(this.basicForm).then((res) => {
        if (res.success) {
          this.$message.success('保存成功')
          this.getDetailInfo()
        }
      })
    },

    // 点击更新时间
    clickTime(index) {
      this.historyList[index].expand =
        !this.historyList[index].expand
    }
  }
}
</script>

<style lang="scss" scoped>
.body {
  display: flex;
  height: 100%;

  &-left {
    flex: 1;
    height: 680px;
  }

  &-right {
    width: 400px;
    height: 680px;
    overflow-y: scroll;
    border-left: 1px solid #f1f1f1;
    padding: 20px;

    .time {
      display: flex;
      justify-content: space-between;
      cursor: pointer;
      margin-bottom: 20px;

      :hover {
        color: #00baff;
      }
    }

    .item {
      margin: 15px 0px;

      &-title {
        margin-top: 10px;
      }

      &-text {
        text-indent: 1em;
      }
    }
  }
}

.project {
  &-part {
    margin-top: 10px;

    &-title {
      margin: 10px 0 15px 15px;
      line-height: 18px;
      font-size: 16px;

      // &::before {
      //   content: '';
      //   width: 6px;
      //   height: 18px;
      //   background: url('~@/assets/images/wisdom-construction/title-pre.png');
      //   position: absolute;
      //   display: inline-block;
      // }
    }

    &-content {
      padding-left: 10px;
    }
  }
}

::v-deep {
  .el-input__inner {
    // background: #f6f9fc !important;
    color: #4c565c !important;
    height: 32px !important;
    width: 320px !important;
    // margin-left: 10px;

    .el-input__icon {
      width: 16px !important;
      height: 16px !important;
      font-size: 16px !important;
      line-height: 40px !important;
      margin-top: -25px !important;
    }

    .el-range-separator {
      width: 20px !important;
      margin-top: -5px !important;
    }

    .el-range-input {
      // background: #f6f9fc !important;
    }
  }

  .el-input.is-disabled .el-input__inner {
    background: #e8eff7 !important;
  }

  .el-button.is-disabled {
    background: #c0c4cc !important;
    border-color: #c0c4cc !important;
  }

  .el-input-group__append {
    position: absolute;
    height: 20px;
    line-height: 20px;
    width: 80px;
    text-align: right;
    top: 4px;
    left: 235px;
    border-color: rgba(0, 0, 0, 0);
    background: rgba(0, 0, 0, 0);
  }

  .el-input__suffix {
    top: 1px !important;
    right: 8px !important;

    .el-input__icon {
      width: 16px !important;
      height: 16px !important;
      font-size: 16px !important;
      line-height: 30px;
    }
    .is-reverse {
      line-height: 15px !important;
    }
  }

  .el-select {
    width: 320px !important;

    .el-input__inner {
      width: 320px !important;
      // margin-left: 10px;
    }

    .el-input__suffix {
      // top: 4px !important;
      .el-input__icon {
        width: 16px !important;
        height: 16px !important;
        font-size: 16px !important;
        line-height: 15px;
      }
      .is-reverse {
        line-height: 35px !important;
      }
    }

    .is-focus {
      .el-input__suffix {
        top: -3px !important;
      }
    }
  }

  .el-textarea__inner {
    width: 320px !important;
    // background: #f6f9fc !important;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
  }

  .el-breadcrumb__inner {
    color: #606266 !important;
    font-weight: 400 !important;
  }
}

.line {
  width: 100%;
  height: 1px;
  margin-top: 10px;
  background: #f1f1f1;
}

.save-btn {
  float: right;
  right: 20px;
  background: #497fa3;
  border: 1px solid #497fa3;
  width: 104px;
  color: white;
  font-size: 14px;
  margin-top: 20px;
}
</style>
